<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>

    <style>

    </style>
</head>

<body>

    <div id="box">


    </div>


    <script src="./js/react.js"></script>
    <script src="./js/react-dom.js"></script>
    <script src="./js/prop-types.js"></script>
    <script src="./js/babel.min.js"></script>

    <script type="text/babel">

        // 需求：书籍列表的组件

        // 1、有状态组件：容器组件，也叫智能组件，主要完成：数据定义，逻辑处理
        class BookList extends React.Component {
            constructor() {
                super();
                // 定义状态：在state属性里
                this.state = {
                    books: [
                        {
                            id: "01001",
                            name: "西游记"
                        },
                        {
                            id: "01002",
                            name: "三国演义"
                        }
                    ]
                }
            }

            // 删除功能
            

            // 修改功能

            render() {
                return (
                    <div>
                        <h1>书籍列表：</h1>
                        <BookDetail books={this.state.books} />
                    </div>
                )
            }
        }

        // 2、无状态组件：也叫展示组件，也叫木偶组件。主要完成UI的展示
        function BookDetail(props) {
            return (<ul>
                {props.books.map((item, index) => (
                    <li key={index}>
                        <p>书号：{item.id}</p>
                        <p>书名：{item.name}</p>
                        <p>
                            <input type="button" value="修改" />
                            <input type="button" value="删除" />
                        </p>
                    </li>
                ))}
            </ul>)
        }

        const root = (<div>
            <h1>组件：</h1>
            <BookList />
        </div>
        );

        ReactDOM.render(root, document.getElementById("box"));


    </script>
</body>

</html>